home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Oberon⁄F™ 1.2 / Preinstalled version / Text / Docu / Mappers (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-07-08  |  20.1 KB  |  384 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. Helvetica
  23. Helvetica
  24. Helvetica
  25. Helvetica
  26. TextMappers
  27. DEFINITION TextMappers;
  28.     IMPORT Views, TextModels;
  29.     CONST
  30.         returnLChars = 0; returnCtrlChars = 1; returnQualIdents = 2; returnViews = 3;
  31.         interpretBools = 4; interpretSets = 5;
  32.         maskViews = 6;
  33.         char = 0; lchar = 1; string = 2; lstring = 3; int = 4; real = 5;
  34.         bool = 6; set = 7; view = 8; tab = 9; line = 10; para = 11;
  35.         eot = 30; invalid = 31;
  36.         charCode = -16; decimal = 10; hexadecimal = 16;
  37.         hideBase = FALSE; showBase = TRUE;
  38.     TYPE
  39.         LONGCHAR = INTEGER;
  40.         String = ARRAY 256 OF CHAR;
  41.         LongString = ARRAY 256 OF LONGCHAR;
  42.         Scanner = RECORD
  43.             opts-: SET;
  44.             rider-: TextModels.Reader;
  45.             type: INTEGER;
  46.             start, lines, paras: LONGINT;
  47.             char: CHAR;
  48.             lchar: LONGCHAR;
  49.             int, base: LONGINT;
  50.             real: LONGREAL;
  51.             bool: BOOLEAN;
  52.             set: SET;
  53.             len: INTEGER;
  54.             string: String;
  55.             lstring: LongString;
  56.             view: Views.View; w, h: LONGINT;
  57.             PROCEDURE (VAR s: Scanner) ConnectTo (text: TextModels.Model);
  58.             PROCEDURE (VAR s: Scanner) Pos (): LONGINT;
  59.             PROCEDURE (VAR s: Scanner) SetPos (pos: LONGINT);
  60.             PROCEDURE (VAR s: Scanner) SetOpts (opts: SET);
  61.             PROCEDURE (VAR s: Scanner) Skip (VAR ch: CHAR);
  62.             PROCEDURE (VAR s: Scanner) Scan
  63.         END;
  64.         Formatter = RECORD
  65.             rider-: TextModels.Writer;
  66.             PROCEDURE (VAR f: Formatter) ConnectTo (text: TextModels.Model);
  67.             PROCEDURE (VAR f: Formatter) Pos (): LONGINT;
  68.             PROCEDURE (VAR f: Formatter) SetPos (pos: LONGINT);
  69.             PROCEDURE (VAR f: Formatter) WriteChar (x: CHAR);
  70.             PROCEDURE (VAR f: Formatter) WriteLChar (x: LONGCHAR);
  71.             PROCEDURE (VAR f: Formatter) WriteInt (x: LONGINT);
  72.             PROCEDURE (VAR f: Formatter) WriteReal (x: REAL);
  73.             PROCEDURE (VAR f: Formatter) WriteLReal (x: LONGREAL);
  74.             PROCEDURE (VAR f: Formatter) WriteString (x: ARRAY OF CHAR);
  75.             PROCEDURE (VAR f: Formatter) WriteLString (x: ARRAY OF LONGCHAR);
  76.             PROCEDURE (VAR f: Formatter) WriteBool (x: BOOLEAN);
  77.             PROCEDURE (VAR f: Formatter) WriteSet (x: SET);
  78.             PROCEDURE (VAR f: Formatter) WriteTab;
  79.             PROCEDURE (VAR f: Formatter) WriteLn;
  80.             PROCEDURE (VAR f: Formatter) WritePara;
  81.             PROCEDURE (VAR f: Formatter) WriteView (v: Views.View);
  82.             PROCEDURE (VAR f: Formatter) WriteIntForm (x: LONGINT; base, minWidth: INTEGER;
  83.             PROCEDURE (VAR f: Formatter) WriteRealForm (x: LONGREAL; precision, minW,
  84.                                                                                         expW: INTEGER; fillCh: CHAR);
  85.             PROCEDURE (VAR f: Formatter) WriteViewForm (v: Views.View; w, h: LONGINT);
  86.             PROCEDURE (VAR f: Formatter) WriteParamMsg (msg, p0, p1, p2: ARRAY OF CHAR);
  87.             PROCEDURE (VAR f: Formatter) WriteMsg (msg: ARRAY OF CHAR)
  88.         END;
  89.     PROCEDURE IsQualIdent (VAR s: ARRAY OF CHAR): BOOLEAN;
  90.     PROCEDURE ScanQualIdent (VAR s: Scanner; VAR x: ARRAY OF CHAR; VAR done: BOOLEAN);
  91. END TextMappers.
  92. TextMappers are mappers that use text riders to scan and format structured text.
  93. CONST returnLChars
  94. Option element
  95. Possible element of Scanner.opts. If present, the scanner will return long characters; otherwise long characters are projected to TextModels.unicode.
  96. CONST returnCtrlChars
  97. Option element
  98. Possible element of Scanner.opts. If present, the scanner will return tab, line, and para characters; otherwise these control characters are treated as white space and read over.
  99. CONST returnQualIdents
  100. Option element
  101. Possible element of Scanner.opts. If present, the scanner will return "qualified identifiers" as a single string; otherwise, the name and period parts of the qualified identifier will be returned individually. (A qualified string, as defined by the language Oberon follows the syntax name ["." name].)
  102. CONST returnViews
  103. Option element
  104. Possible element of Scanner.opts. If present, the scanner will return embedded views; otherwise these are treated as white space and read over.
  105. CONST interpretBools
  106. Option element
  107. Possible element of Scanner.opts. If present, the scanner will recognize boolean truth values "$TRUE" and "$FALSE", as output by the formatter when writing Boolean values; otherwise "$", "TRUE", and "FALSE" are returned individually, without interpretation.
  108. CONST interpretSets
  109. Option element
  110. Possible element of Scanner.opts. If present, the scanner will recognize set values: sets of integers in the range MIN(SET) .. MAX(SET) as defined by the language Oberon; otherwise "{", ".", and enclosed integers will be returned individually. (The syntax of set values is {" integer [".." integer "]" { "," integer [".." integer] "}.)
  111. CONST maskViews
  112. Option element
  113. Possible element of scanner.opts. If present, the scanner will try to interpret a view as a character code, if the view has a preferred character code. Otherwise, the view is returned.
  114. CONST char
  115. Possible value of scanner.type, signalling that a plain character has been scanned. A character is returned in this class if it does not form a valid first character of any of the structured scan types below.
  116. CONST lchar
  117. Possible value of scanner.type, signalling that a long character has been scanned.
  118. CONST string
  119. Possible value of scanner.type, signalling that a string has been scanned.
  120. CONST lstring
  121. Possible value of scanner.type, signalling that a long string has been scanned.
  122. CONST int
  123. Possible value of scanner.type, signalling that an integer has been scanned.
  124. CONST real
  125. Possible value of scanner.type, signalling that a real has been scanned.
  126. CONST bool
  127. Possible value of scanner.type, signalling that a Boolean has been scanned.
  128. CONST set
  129. Possible value of scanner.type, signalling that a set has been scanned.
  130. CONST view
  131. Possible value of scanner.type, signalling that an embedded view has been scanned.
  132. CONST tab
  133. Possible value of scanner.type, signalling that a tab character has been scanned.
  134. CONST line
  135. Possible value of scanner.type, signalling that a line character has been scanned.
  136. CONST para
  137. Possible value of scanner.type, signalling that a para character has been scanned.
  138. CONST eot
  139. Possible value of scanner.type, signalling that the most recent call to Scan hit the end of the text.
  140. CONST invalid
  141. Possible value of scanner.type, signalling that the most recent call to Scan encountered a syntactically ill formed sequence.
  142. CONST charCode
  143. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers following the syntax of Oberon numerical character literals. (For example, 0DX is the code for line, and 37X the code for "7".)
  144. CONST decimal
  145. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers as decimal literals.
  146. CONST hexadecimal
  147. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers as hexadecimal literals.
  148. CONST hideBase
  149. Possible value for parameter showBase of formatter.WriteIntForm, asking for suppresion of the base indicator.
  150. CONST showBase
  151. Possible value for parameter showBase of formatter.WriteIntForm, asking for output of the base indicator.
  152. TYPE LONGCHAR
  153. Type of long characters.
  154. TYPE String
  155. Strings of characters as detectable by scanners.
  156. TYPE LongString
  157. Strings of long characters as detectable by scanners.
  158. TYPE Scanner
  159. Scanners are connectable to texts. They allow to scan the sequence of characters and embedded views which form a text for recognized structured subsequences (symbols). The various symbols that a scanner can recognize are defined in terms of scan types (cf. the constants above).
  160. opts-: SET
  161. The scanning options, drawn from the set {returnLChars, returnCtrlChars, returnQualIdents, returnViews, interpretBools, interpretSets, maskViews}.
  162. rider-: TextModels.Reader
  163. The rider connecting the scanner to the text. The rider state is used by the scanner as a single element look
  164. ahead buffer. A sequence of rider.Read or rider.ReadPrev, or positioning the rider followed by rider.Read are all legal manipulations of that look
  165. ahead state.
  166. type: INTEGER
  167. Type of symbol scanned most recently.
  168. start: LONGINT
  169. Starting position of the symbol scanned most recently. Set by scanner.Scan after skipping initial white space.
  170. lines, paras: LONGINT
  171. Number of lines (line characters) and paragraphs (para characters) passed by the scanner since being connected. Updated by scanner.Skip (called initially in scanner.Scan) when skipping white space.
  172. char: CHAR    valid if type = char
  173. Character scanned most recently.
  174. lchar: LONGCHAR    valid iff type IN {char, lchar}
  175. Long character scanned most recently.
  176. int, base: LONGINT    valid iff type = int
  177. Integer scanned most recently, and the base that was used for its formatting. The string representation of the scanned integer is available in (len, string) after scanning.
  178. real: LONGREAL    valid iff type = real
  179. Real scanned most recently.
  180. bool: BOOLEAN    valid iff type = bool
  181. Boolean scanned most recently.
  182. set: SET    valid iff type = set
  183. Set scanned most recently.
  184. len: INTEGER    valid iff type IN {string, lstring, int}
  185. Length of string or lstring field, depending on type.
  186. string: String    valid iff type IN {string, int, bool}
  187. String of characters scanned most recently.
  188. lstring: LongString    valid iff type IN {string, lstring}
  189. String of long characters scanned most recently.
  190. view: Views.View; w, h: LONGINT    valid iff type = view
  191. View scanned most recently, and its width and height.
  192. PROCEDURE (VAR s: Scanner) ConnectTo (text: TextModels.Model)
  193. Disconnect the scanner from the text it was connected to previously (if any), and connect the scanner to the given text (if any).
  194. text = NIL
  195.     s.rider = NIL
  196. text # NIL
  197.     s.rider.Base() = text
  198.     s.Pos() = 0
  199.     s.opts = {}
  200. PROCEDURE (VAR s: Scanner) Pos (): LONGINT
  201. Current position of the scanner's look
  202. ahead rider.
  203. s.rider # NIL    (not explicitly checked)
  204. result = s.rider.Pos()
  205. PROCEDURE (VAR s: Scanner) SetPos (pos: LONGINT)
  206. Reposition the scanner.
  207. s.rider # NIL    (not explicitly checked)
  208. preconditions of s.rider.SetPos
  209. s.Pos() = pos
  210. s.start = pos
  211. s.lines = 0
  212. s.paras = 0
  213. s.type = invalid
  214. PROCEDURE (VAR s: Scanner) SetOpts (opts: SET)
  215. Set scanning options.
  216. s.opts = opts
  217. PROCEDURE (VAR s: Scanner) Skip (VAR ch: CHAR)
  218. Skip white space, as specified by the scanning options picked from {returnLChars, returnCtrlChars, returnViews}.
  219. s.rider # NIL    (not explicitly checked)
  220. ~s.rider.eot
  221.     s.start = s.rider.Pos() - 1
  222. s.rider.eot
  223.     s.start = s.rider.Base().Length()
  224.     s.type = eot
  225. PROCEDURE (VAR s: Scanner) Scan
  226. Scan the text for the next symbol as specified by the scanning options.
  227. s.rider # NIL    (not explicitly checked)
  228. s.rider.eot OR s.Pos() = s.start + Length(symbol) + 1
  229. TYPE Formatter
  230. Formatters connectable to texts in order to write formatted entities to the text.
  231. rider-: TextModels.Writer
  232. The rider connecting the formatter to the text.
  233. PROCEDURE (VAR f: Formatter) ConnectTo (text: TextModels.Model)
  234. Disconnect the formatter from the text it was previously connected to (if any), and connect it to the given text (if any).
  235. text = NIL
  236.     f.rider = NIL
  237. text # NIL
  238.     f.rider # NIL
  239.     f.rider.Base() = text
  240.     f.Pos() = text.Length()
  241. PROCEDURE (VAR f: Formatter) Pos (): LONGINT
  242. Position of the formatter.
  243. f.rider # NIL    (not explicitly checked)
  244. PROCEDURE (VAR f: Formatter) SetPos (pos: LONGINT)
  245. Reposition the formatter.
  246. f.rider # NIL    (not explicitly checked)
  247. f.Pos() = pos
  248. PROCEDURE (VAR f: Formatter) WriteChar (x: CHAR)
  249. Write character x. For control characters the numerical literal form enclosed in spaces is written.
  250. f.rider # NIL    (not explicitly checked)
  251. x >= " "  &  x # 7FX
  252.     character written as is
  253. x < " "  OR  x = 7FX
  254.     " " code(x) " " written
  255. PROCEDURE (VAR f: Formatter) WriteLChar (x: LONGCHAR)
  256. Not yet implemented.
  257. PROCEDURE (VAR f: Formatter) WriteInt (x: LONGINT)
  258. Write integer in default format.
  259. Except for performance, equivalent to:
  260.     f.WriteIntForm(x, decimal, 0, TextModels.digitspace, showBase)
  261. PROCEDURE (VAR f: Formatter) WriteReal (x: REAL)
  262. Write real in default format.
  263. Except for performance, equivalent to:
  264.     f.WriteRealForm(x, 7, 0, 0, TextModels.digitspace)
  265. PROCEDURE (VAR f: Formatter) WriteLReal (x: LONGREAL)
  266. Write long real in default format.
  267. Except for performance, equivalent to:
  268.     f.WriteRealForm(x, 16, 0, 0, TextModels.digitspace)
  269. PROCEDURE (VAR f: Formatter) WriteString (x: ARRAY OF CHAR)
  270. Write string of characters.
  271. Except for performance, equivalent to:
  272.     VAR i: INTEGER;
  273.     i := 0; WHILE x[i] # 0X DO f.WriteChar(x[i]); INC(i) END
  274. PROCEDURE (VAR f: Formatter) WriteLString (x: ARRAY OF LONGCHAR)
  275. Write string of long characters.
  276. Except for performance, equivalent to:
  277.     VAR i: INTEGER;
  278.     i := 0; WHILE x[i] # 0 DO f.WriteLChar(x[i]); INC(i) END
  279. PROCEDURE (VAR f: Formatter) WriteBool (x: BOOLEAN)
  280. Write Boolean.
  281. Except for performance, equivalent to:
  282.     IF x THEN f.WriteString("$TRUE") ELSE f.WriteString("$FALSE") END
  283. PROCEDURE (VAR f: Formatter) WriteSet (x: SET)
  284. Write set.
  285. Except for performance, equivalent to:
  286.     VAR i: INTEGER;
  287.     f.WriteChar("{"); i := MIN(SET);
  288.     WHILE x # {} DO
  289.         IF i IN x THEN f.WriteInt(i); EXCL(x, i);
  290.             IF (i + 2 <= MAX(SET)) & (i+1 IN x) & (i+2 IN x) THEN f.WriteString("..");
  291.                 x := x - {i+1, i+2}; INC(i, 3);
  292.                 WHILE (i <= MAX(SET)) & (i IN x) DO EXCL(x, i); INC(i) END;
  293.                 f.WriteInt(i-1)
  294.             END;
  295.             IF x # {} THEN f.WriteString(", ") END
  296.         END;
  297.         INC(i)
  298.     END;
  299.     f.WriteChar("}")
  300. PROCEDURE (VAR f: Formatter) WriteTab
  301. Write tab character.
  302. Except for performance, equivalent to:
  303.     f.rider.WriteChar(TextMappers.tab)
  304. PROCEDURE (VAR f: Formatter) WriteLn
  305. Write line character.
  306. Except for performance, equivalent to:
  307.     f.rider.WriteChar(TextMappers.line)
  308. PROCEDURE (VAR f: Formatter) WritePara
  309. Write para character.
  310. Except for performance, equivalent to:
  311.     f.rider.WriteChar(TextMappers.para)
  312. PROCEDURE (VAR f: Formatter) WriteView (v: Views.View)
  313. Embed view.
  314. Except for performance, equivalent to:
  315.     f.WriteViewForm(v, Views.undefined, Views.undefined)
  316. v # NIL    20
  317. v.context = NIL    21
  318. PROCEDURE (VAR f: Formatter) WriteIntForm (x: LONGINT; base, minWidth: INTEGER;
  319.                                                                                         fillCh: CHAR; showBase: BOOLEAN)
  320. Write integer x. The numeral string used to represent the number is relative to base base. The total representation form will at least have a width of minWidth characters, where padding (if required) takes place to the left using characters as specified by fillCh. If non
  321. decimal, the base can be requested to form part of the representation using showBase. The special value base = charCode renders the base suffix "X", while base = hexadecimal renders the suffix "H". All other non
  322. decimal bases are represented by a trailing "%" followed by the decimal numerical literal representing the base value itself. Non
  323. decimal representations of negative integers are formed using a base
  324. complement form of width minWidth. E.g., x = -3 renders for base = 16 and minWidth = 2 as "FD".
  325. f.rider # NIL    (not explicitly checked)
  326. base = charCode  OR  base >= 2    20
  327. base <= 16    21
  328. minWidth >= 0    22
  329. PROCEDURE (VAR f: Formatter) WriteRealForm (x: LONGREAL; precision, minW,
  330.                                                                                             expW: INTEGER; fillCh: CHAR)
  331. Write real x. The numeral string used to represent the number is either in fixed point or in scientific format.
  332. f.rider # NIL    (not explicitly checked)
  333. 0 < precision <= 16    20
  334. 0 <= minW < LEN(s)    21
  335. -LEN(s) < expW <= 3    22
  336. precision denotes the number of valid decimal places (usually 7 for reals and 16 for long reals).
  337. minW denotes the minimal length in characters. If necessary, preceding fillCh will be inserted.
  338. expW > 0: exponential format (scientific) with at least expW digits in the exponent.
  339. expW = 0: fixpoint or floatingpoint format, depending on x.
  340. expW < 0: fixpoint format with -expW digits after the decimal point.
  341. Numbers are always rounded to the last valid and visible digit.
  342. PROCEDURE (VAR f: Formatter) WriteViewForm (v: Views.View; w, h: LONGINT)
  343. Embed a view with width w and height h. w and h may have the value Views.undefined.
  344. f.rider # NIL    (not explicitly checked)
  345. v # NIL    20
  346. v.context = NIL    21
  347. PROCEDURE (VAR f: Formatter) WriteParamMsg (msg, p0, p1, p2: ARRAY OF CHAR)
  348. Write a parameterized message string mapped by the Dialog.MapParamString facility. The resulting string is allowed to contain line, para and tab characters, all of which will be written as such.
  349. f.rider # NIL    (not explicitly checked)
  350. PROCEDURE (VAR f: Formatter) WriteMsg (msg: ARRAY OF CHAR)
  351. Write a message string mapped by the Dialog.MapParamString facility.
  352. Except for performace, equivalent to:
  353.     f.WriteParamMsg(msg, "", "", "")
  354. PROCEDURE IsQualIdent (VAR s: ARRAY OF CHAR): BOOLEAN
  355. Test whether the string s fulfills the syntax of an Oberon qualident, i.e. ident ["." ident].
  356. PROCEDURE ScanQualIdent (VAR s: Scanner; VAR x: ARRAY OF CHAR;
  357.                                                         VAR done: BOOLEAN)
  358. Assuming that the scanner returned a string, check if the succeeding symbols can be consumed to scan a qualident. If the scanned string is not a qualident, the scanner is reset the position it had before the call to ScanQualIdent.
  359. s'.type = string
  360.     IsQualIdent(s'.string)
  361.         done = TRUE
  362.         x = s'.string
  363.         s = s'
  364.     ~IsQualIdent(s'.string)
  365.         s'.Scan.type = char  &  s'.Scan.char = "."
  366.             s'.Scan.Scan.type = string & (s'.len + 1 + s'.Scan.Scan.len < LEN(x))
  367.                 done = TRUE
  368.                 x = s'.string + "." + s'.Scan.Scan.string
  369.                 s = s'.Scan.Scan
  370.             s'.Scan.Scan.type # string OR (s'.len + 1 + s'.Scan.Scan.len >= LEN(x))
  371.                 done = FALSE
  372.         s'.Scan.type # char  OR  s'.Scan.char # "."
  373.             done = FALSE
  374. s'.type # string
  375.         done = FALSE
  376. ~done
  377.     s = s'.SetPos(s'.start).Scan()
  378. TextControllers.StdCtrlDesc
  379. TextControllers.ControllerDesc
  380. Containers.ControllerDesc
  381. Controllers.ControllerDesc
  382. Helvetica
  383. Documents.ControllerDesc
  384.